package com.tianbao54.springboot.mybatis.controller;

import com.tianbao54.springboot.mybatis.mapper.UserMapper;
import com.tianbao54.springboot.mybatis.model.User;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;

    @Autowired
    private UserMapper userMapper;

    @GetMapping("/user/{id}")
    public User getUser (@PathVariable int id) {
        return userMapper.getUserById(id);
    }

    @GetMapping("/user2/{id}")
    public User getUser2 (@PathVariable int id) {
        return sqlSessionTemplate.selectOne("com.tianbao54.springboot.mybatis.mapper.UserMapper.getUserById",id);
    }
}
